﻿using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace ILoliU3
{
    public static class ApplicationLogger
    {
        public static string LogFileName = @"AppLog.log";

        static void DefaultLogCallback(string condition, string stackTrace, LogType type)
        {
            using (StreamWriter sw = new StreamWriter(LogFileName, true))
            {
                sw.WriteLine("[" + DateTime.Now + "]");
                sw.WriteLine("["+ condition +"]["+ type +"]");
                sw.WriteLine(stackTrace);
                sw.WriteLine();

                Debug.LogError("[" + condition + "][" + type + "]\n" + stackTrace + "\n");
            }
        }

        public static void RegisterLogger()
        {
            Application.RegisterLogCallback(DefaultLogCallback);
        }

        public static void RegisterLogger(Application.LogCallback Logger)
        {
            Application.RegisterLogCallback(Logger);
        }

        public static void RegisterLoggerThreaded()
        {
            Application.RegisterLogCallbackThreaded(DefaultLogCallback);
        }

        public static void RegisterLoggerThreaded(Application.LogCallback Logger)
        {
            Application.RegisterLogCallbackThreaded(Logger);
        }
    }
}
